#ifndef QMLCONNCPP_H
#define QMLCONNCPP_H
#include <QObject>
#include <QDebug>
#include "../serialQuickCommon/globalobject.h"
#include "../serialQuickCommon/station.h"



class qmlConnCpp : public QObject
{

    Q_OBJECT

    Q_PROPERTY(QString qmlDevice READ readqmlDevice NOTIFY manChanged)
public:
    qmlConnCpp(){}

    QString readqmlDevice(){return qmlEditDevice;}
    Q_INVOKABLE void setqmlDevice(int deviceid){}

    Q_INVOKABLE QString getqmlDevice(int deviceid) {qmlEditDevice=GetData::getJSON_Device(deviceid); return qmlEditDevice;}
    Q_INVOKABLE QString getqmlDeviceProtocolGroup() {
        QString strlist="[";
        QVariantList varlist=GetData::getVariant_DeviceProtocolGroup();

        for(int i=0;i<varlist.size();i++)
        {
            if(0!=i) strlist+=",";
            strlist+="\""+varlist.at(i).value<QVariantMap>()["protocolGroup"].toString()+"\"";
        }
        return strlist+"]";
    }

    Q_INVOKABLE QString getqmlDeviceProtocolByGroup(QString group) {

//        QString strlist="[";
//        QVariantList varlist=GetData::getVariant_DeviceProtocolByGroup(group);

//        return JsonHelper::getJson(varlist);
//        for(int i=0;i<varlist.size();i++)
//        {
//            if(0!=i) strlist+=",";
//            strlist+="{ \"protocolId\": \""+varlist.at(i).value<QVariantMap>()["protocolId"].toByteArray().toHex()+"\", \"protocolName\": \""+varlist.at(i).value<QVariantMap>()["protocolName"].toString()+"\", \"protocolText\": \""+varlist.at(i).value<QVariantMap>()["protocolText"].toString()+"\" }";
//        }
//        return strlist+"]";

        return JsonHelper::getJson(GetData::getVariant_DeviceProtocolByGroup(group));
    }

    Q_INVOKABLE QString getqmlDeviceProtocolById(QString id) {return JsonHelper::getJson(GetData::getVariant_DeviceProtocol(id));}
    Q_INVOKABLE QString getqmlServerSendTask() {return JsonHelper::getJson(GetData::getVariant_ServerSendTask());}



    Q_INVOKABLE bool setsqlDevice(QString json){return SetData::Update_Device(json);}


    QString man() {return   QString("[{\"name\":\"Joy\",\"age\":30},{\"name\":\"James\",\"age\":36},{\"name\":\"Lily\",\"age\":20}]");}


    Q_INVOKABLE void clickItem(int index){qDebug()<<index;}
    Q_INVOKABLE void clickDeviceItem(int index){Station::clickDeviceItem(index);}
    Q_INVOKABLE void clickHostItem(int index){Station::clickHostItem(index);}
    Q_INVOKABLE void serialRefresh(){portlist.setText(serialbox.SerialRefresh(true));}
    Q_INVOKABLE void goUpdate(){Station::goUpDate();}
signals:
    void  manChanged();
private:
    QString qmlEditDevice;
};


#endif // QMLCONNCPP_H
